package com.vichat.business.thread;

import com.alibaba.fastjson.JSONObject;
import com.vichat.business.entity.VcAlarm;
import com.vichat.common.constant.GlobalConstant;
import com.vichat.common.signal.CmdUtil;
import com.vichat.common.vo.PageFilter;
import com.vichat.room.entity.RoomMember;
import com.vichat.room.service.IRoomService;
import com.vichat.user.entity.UserBasic;
import com.vichat.user.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;

/**
 * Created by ranjx on 2018/04/08.
 */
public class AlarmSendThread implements Runnable {
    private static Logger logger = LoggerFactory.getLogger(AlarmSendThread.class);
    private IRoomService roomService;
    private long rid;
    private String type;
    private VcAlarm alarm;

    public AlarmSendThread(IRoomService roomService, long rid, String type,VcAlarm alarm ) {
        this.roomService = roomService;
        this.rid = rid;
        this.type = type;
        this.alarm = alarm;
    }

    @Override
    public void run() {
        try {
            RoomMember queryBean = new RoomMember();
            queryBean.setRid(rid);
            List<RoomMember> roomMembers = roomService.queryRoomMemers(queryBean, PageFilter.getMaxPageFilter());
             if (!roomMembers.isEmpty()) {
                for (RoomMember roomMember : roomMembers) {
                    CmdUtil.sendImMsg(10000, roomMember.getUid(), 0, type, JSONObject.toJSONString(alarm));
                }
            }
        } catch (Exception e) {
            logger.error("发送消息失败>>>>>>" + e.getMessage(), e);
        }
    }

}
